import 'lib_cloud_storage_platform_interface.dart';

class LibCloudStorage {
  static Future<String?> getPlatformVersion() {
    return LibCloudStoragePlatform.instance.getPlatformVersion();
  }

  static const String prefix_file = "kai_private_key"; // 私钥文件的前缀
  /**
   * 谷歌登录
   */
  static Future<GoogleLoginResult> startGoogleLogin({String? clientID}) async {
    return LibCloudStoragePlatform.instance
        .startGoogleLogin(clientID: clientID);
  }

  /**
   * 私钥上传到谷歌云盘
   * 要求 返回文件id ；
   */
  static Future<String> uploadToGoogleCloud(
      String email, String fileContent, String uid, String salt) {
    String fileName = "${prefix_file}_${uid}_${salt}";

    // String fileName = "${prefix_file}_${DateTime.now().millisecondsSinceEpoch}";

    return LibCloudStoragePlatform.instance
        .uploadToGoogleCloud(email, fileName, fileContent);
  }

  /**
   * 查询谷歌云盘中文件列表
   */
  static Future<FileList> queryGoogleDriveList(String email) {
    return LibCloudStoragePlatform.instance
        .fetchGoogleDriveFileList(email, prefix_file);
  }

  /**
   * 下载私钥
   */
  static Future<String> googleCloudDownloadFile(String email, String fileId) {
    return LibCloudStoragePlatform.instance
        .fetchGoogleDriveFileById(email, fileId);
  }
}
